<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Cursosyeventos extends CI_Controller {
	
	public function __construct()
	{
		parent::__construct();
		$this->load->model('cursosyeventos_model');
		$this->load->library('session');
		$this->load->library('tank_auth');
		$this->load->helper('url');
		$this->load->helper('form');
		$this->load->helper('date');
		$this->load->helper('text');
		
		// prevent caching
		$this->output->set_header('Last-Modified:'.gmdate('D, d M Y H:i:s').'GMT');
		$this->output->set_header('Cache-Control: no-store, no-cache, must-revalidate');
		$this->output->set_header('Cache-Control: post-check=0, pre-check=0',false);
		$this->output->set_header('Pragma: no-cache');
		
		// if no session, redirect to login page		
		if(!$this->tank_auth->is_logged_in())
		{
			redirect('admin/login', 'refresh');
		}
	}
	
	public function index()
	{
		if($this->session->flashdata('message'))
		{
			$data['message'] = $this->session->flashdata('message');
		}
		$data['result'] = $this->cursosyeventos_model->get();		
		$data['title'] = 'Administrador - Starscamp';
		$data['session'] = array('username'=>ucfirst($this->tank_auth->get_username()));
		
		$this->load->view('admin/templates/header', $data);
		$this->load->view('admin/cursosyeventos', $data);
		$this->load->view('admin/templates/footer', $data);
	}
	
	public function registro($id)
	{				
		// This method will have the credentials validation
		$this->load->library('form_validation');		
		$this->form_validation->set_rules('id_evento', 'Evento', 'trim|xss_clean');
		
		if($this->form_validation->run())
		{			
			$explode = explode('/', $this->input->post('id_evento'));
			if($this->input->post('id_evento'))
			{
				$input = array(
					'type'=>$explode[0],
					'id_evento'=>$explode[1]
				);
			}
			else
			{
				$input = array(
					'type'=>NULL,
					'id_evento'=>NULL
				);
			}
			$this->cursosyeventos_model->update($input, $id);
			$this->session->set_flashdata('message', 'Se ha modificado un registro');
			redirect('admin/cursosyeventos', 'refresh');
		}
		$data['title'] = 'Administrador - Starscamp';
		$data['session'] = array('username'=>ucfirst($this->tank_auth->get_username()));
		$data['result'] = $this->cursosyeventos_model->get_all();
		
		$this->load->view('admin/templates/header', $data);
		$this->load->view('admin/cursosyeventos-registro', $data);
		$this->load->view('admin/templates/footer', $data);
	}
}

/* End of file cursosyeventos.php */
/* Location: ./application/controllers/admin/cursosyeventos.php */